﻿Imports System.Activities
Imports System.Management
Imports System.Activities.Presentation.Metadata
Imports System.ComponentModel
Imports System.Activities.Presentation
Imports System.Drawing

Public Class WMISYSGetAntiSpywareProduct
    Inherits WMIExecuteActivityBase

    Public Property IsVistaLater As InArgument(Of Boolean)

    Private _laterVista As Boolean = True


    Public Sub New()
        Me.DisplayName = My.Resources.GetAntiSpywareProductDisplayName
    End Sub

    Protected Overrides Function BeginExecute(ByVal context As AsyncCodeActivityContext, ByVal callback As AsyncCallback, ByVal state As Object) As IAsyncResult
        MyBase._target = "AntiSpywareProduct"
        MyBase._where = ""
        MyBase._service = "SecurityCenter"
        Dim lateVista = context.GetValue(Me.IsVistaLater)
        If lateVista Then MyBase._service += "2"

        Return MyBase.BeginExecute(context, callback, state)
    End Function

    Protected Overrides Function CreateScope(wmScope As ManagementScope) As ManagementScope
        If wmScope Is Nothing Then
            wmScope = New ManagementScope("\\" + My.Computer.Name + "\root\" + _service)
        End If
        If Not wmScope.IsConnected Then wmScope.Connect()
        Return wmScope
    End Function

    Protected Overrides Sub CacheMetadata(metadata As CodeActivityMetadata)
        MyBase.CacheMetadata(metadata)
        Dim build As New AttributeTableBuilder
        'WMISYSGetFirewallProduct Activity
        build.AddCustomAttributes(GetType(WMISYSGetFirewallProduct),
                                      New DesignerAttribute(GetType(WMIDefaultActivityDesigner), GetType(ActivityDesigner)),
                                      New ToolboxBitmapAttribute(GetType(WMISYSGetFirewallProduct), "WmiDefault.png"))
        build.AddCustomAttributes(GetType(WMISYSGetAntiSpywareProduct), "IsVistaLater",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New DisplayNameAttribute(My.Resources.IsVistaLaterDisplay),
                                      New DescriptionAttribute(My.Resources.IsVistaLaterDescription))

        MetadataStore.AddAttributeTable(build.CreateTable)
    End Sub

End Class
